<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>作业实现</title>
  <script src="../js/vue.js"></script>
  <style>
    .active {
      color: red;
    }
  </style>
</head>

<!-- 自己实现见：03-动态绑定属性\04-作业(v-foir和v-bind结合).html -->

<body>
  <!-- 需求：点击列表中哪一项，那么该项文字变成红色 -->
  <div id="app">
    <h2>2021上半年电影最佳：</h2>
    <ul>
      <li v-for="(item,index) in movies" :class="{active: count === index}" @click="changeColor(index)">
        {{ item }}
      </li>
    </ul>
  </div>

  <script>
    var vm = new Vue({
      el: '#app',
      data: {
        // 初始count
        count: null,
        movies: ['《你好，李焕英》', '《我的姐姐》', '《送你一朵小红花》', '《拆弹专家2》', '《哥斯拉大战金刚》', '《唐人街探案3》']
      },
      methods: {
        changeColor(index) {
          this.count = index;
        }
      }
    });
  </script>
</body>

</html>